package com.yyh.xiancheng2;

public class Test2 {
    public static void main(String[] args) {
        Runnable r = new MyTask();
        Thread t1 = new Thread(r, "线程1");
        Thread t2 = new Thread(r, "线程2");
        t1.start();
        t2.start();
    }

}
class MyTask implements Runnable{
    @Override
    public void run() {
        for (int i = 1; i <= 100; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "：" + i);
            //线程让步
            if (i == 50){
                Thread.yield();
            }
        }
    }
}
